<?php
include '../config/config.php';
include '../lib/user.php';

$config=new config();
$config->connect();

session_start();
if (!isset($_SESSION['MM_Username'])){
	$togo="../login.php";
	header ("Location:$togo");
}
if ($_POST){
  if ($_POST['password_lama']!="" && $_POST['password_baru']!="" && $_POST['password_baru2']!=""){
		$User_Dao = new User_Dao();
		$user=new User();
		$cek = $User_Dao->get_id($_SESSION['MM_Id']);
		if($cek->password==$_POST['password_lama']){
			$user->password=$_POST['password_baru']; 
			$user->id=$_SESSION['MM_Id'];
			$User_Dao->edit_pass($user);
			$config->close();
			echo "<script>alert('Data berhasil disimpan');</script>";
		}else{
			echo "<script>alert('Password lama tidak valid!');</script>";
		}
	} else {
		echo "Isikan data yang masih kosong terlebih dahulu!";
	}
		
}
?>
<?php include("header_admin.php") ?>
<?php include("menu_kiri_admin.php") ?>
<style type="text/css">
<!--
.style1 {
	font-size: 24px;
	font-weight: bold;
	color: #990066;
}
-->
</style>
<div id="body"><div class="topbox">
  <p align="center" class="style1">Ubah Password </p>
  <p>Silahkan Merubah Password anda untuk keamanan akses website</p>
  Password Lama : 
  <form id="form1" name="form1" method="post" action="" name="ubahpassword">
    <label>
      <input type="password" name="password_lama" id="password_lama" />
    </label>
    <p>Password Baru :</p>
    <p>
      <label>
      <input type="password" name="password_baru" id="password_baru" />
      </label>
    </p>
    <p>Konfirmasi Password Baru :</p>
    <p>
      <input type="password" name="password_baru2" id="password_baru2" />
    </p>
    <p>
      <label></label>
    </p>
    <p align="left">
      <input type="submit" name="batal" id="batal" value="Batal" />
      <label>
       <input type="submit" name="Simpan" id="Simpan" value="Simpan" onclick="return validate_form();" />
      </label>
    </p>
  </form>         
     
</div>             
</div>
<div align="left"><script>
	function validate_form(){
		var pasbar = $("#password_baru").val();
		var pasbar2 = $("#password_baru2").val();
		var paslam = $("#password_lama").val();
		if(pasbar=="" || pasbar2=="" || paslam==""){
			alert('Lengkapi form Anda!');
			return false;
		}else{
			if(pasbar==pasbar2){
				document.ubahpassword.submit();
			}else{
				alert('Password baru dan konfirmasi password baru tidak sama !');
				return false;
			}
		}
	}
</script>
          
         <div class="clear"></div>
         <?php include("../footer.php") ?>
		
		</div>